<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class KategoriRapor extends MY_Controller {

	function __construct()
    {
		// Call the Model constructor
        parent::__construct();
		if($this->session->userdata('login') === TRUE && in_array(123,$this->access)){
			$log['activity']='VIEW';
			$log['information']='Masuk ke menu : '.$this->uri->uri_string();
			$this->model_log->add($log);
		}else{
			$log['activity']='VIEW';
			$log['information']='Tidak diijinkan : '.$this->uri->uri_string();
			$this->model_log->add($log);
			redirect('sessions/login');
		}
		
		$this->config->set_item("menu_active","kategori-rapor");
		$this->config->set_item("menu_root","guru-pelajaran");
    }
	
	public function index()
	{
		$mdl = $this->load->model('model_kategori_rapor');
		$mdl2 = $this->load->model('departemen/model_departemen');
		
		$departemen_id = 0;
		$data['departemen']= $mdl2->get_departemen(1);
		
		if(isset($_POST['departemen'])){
			$departemen_id = $_POST['departemen'];
		}else if($this->session->flashdata('departemen_id')){
			$departemen_id = $this->session->flashdata('departemen_id');
		}else{
			foreach($data['departemen']->result_array() as $row){
				$departemen_id = $row['departemen_id'];
				break;
			}
		}
		$data['data']= $mdl->get_all($departemen_id);
		$data['departemen_id'] = $departemen_id;
		
		$params['content'] = $this->load->view('list',$data,TRUE);
		$params['footer']['js_plugin'] = $this->load->view('js_plugin','',TRUE);
		$params['header']['css_plugin'] = $this->load->view('css_plugin','',TRUE);
		
		echo modules::run('template', $params);	
	}
	
	public function form($departemen_id,$id=0)
	{
		$mdl = $this->load->model('model_kategori_rapor');
		$mdl_departemen = $this->load->model('departemen/model_departemen');
		
		if($id!=0){
			$id = decode($id);
		}
		$departemen_id = decode($departemen_id);
		
		if(isset($_POST['data'])){
			$data = $_POST['data'];
			
			if($id == 0){	
				$mdl->add($data);
				
				$log['activity']='INSERT';
				$log['information']='Insert Kategori Rapor pendidikan dengan data :'.json_encode($_POST['data']);
			}else{
				$mdl->edit($id,$data);			
				$log['activity']='UPDATE';
				$log['information']="UPDATE Kategori Rapor pendidikan id $id dengan data :".json_encode($_POST['data']);
			}
			
			$this->model_log->add($log);
			$this->session->set_flashdata('departemen_id', $departemen_id);
			
			redirect('kategoriRapor');
		}
		
		$data['data']= $mdl->get_by($id);
		$data['departemen'] = $mdl_departemen->get_departemen(1);
		$data['departemen_id'] = $departemen_id;
		
		$params['content'] = $this->load->view('form',$data,TRUE);
		$params['footer']['js_plugin'] = $this->load->view('js_plugin','',TRUE);
		$params['header']['css_plugin'] = $this->load->view('css_plugin','',TRUE);
		
		echo modules::run('template', $params);	
	}
	
	public function delete($departemen_id,$id=0){
		
		$id = decode($id);
		$departemen_id = decode($departemen_id);
				
		$mdl = $this->load->model('model_kategori_rapor');		
		$mdl->delete($id);
		
		$this->session->set_flashdata('departemen_id', $departemen_id);
		
		redirect('kategoriRapor');
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */